package com.ruoyi.custom.kami.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.custom.kami.domain.CmsKami;
import com.ruoyi.custom.kami.service.ICmsKamiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * listController
 * 
 * @author ruoyi
 * @date 2024-04-24
 */
@RestController
@RequestMapping("/kaimi/kami")
public class CmsKamiController extends BaseController
{
    @Autowired
    private ICmsKamiService cmsKamiService;

    /**
     * 查询list列表
     */
    @PreAuthorize("@ss.hasPermi('kaimi:kami:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsKami cmsKami)
    {
        startPage();
        List<CmsKami> list = cmsKamiService.selectCmsKamiList(cmsKami);
        return getDataTable(list);
    }

    /**
     * 导出list列表
     */
    @PreAuthorize("@ss.hasPermi('kaimi:kami:export')")
    @Log(title = "list", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsKami cmsKami)
    {
        List<CmsKami> list = cmsKamiService.selectCmsKamiList(cmsKami);
        ExcelUtil<CmsKami> util = new ExcelUtil<CmsKami>(CmsKami.class);
        util.exportExcel(response, list, "list数据");
    }

    /**
     * 获取list详细信息
     */
    @PreAuthorize("@ss.hasPermi('kaimi:kami:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmsKamiService.selectCmsKamiById(id));
    }

    /**
     * 新增list
     */
    @PreAuthorize("@ss.hasPermi('kaimi:kami:add')")
    @Log(title = "list", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsKami cmsKami)
    {
       // return toAjax(cmsKamiService.insertCmsKami(cmsKami));
        return toAjax(cmsKamiService.buildCarMi(cmsKami));
    }

    /**
     * 修改list
     */
    @PreAuthorize("@ss.hasPermi('kaimi:kami:edit')")
    @Log(title = "list", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsKami cmsKami)
    {
        return toAjax(cmsKamiService.updateCmsKami(cmsKami));
    }

    /**
     * 删除list
     */
    @PreAuthorize("@ss.hasPermi('kaimi:kami:remove')")
    @Log(title = "list", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsKamiService.deleteCmsKamiByIds(ids));
    }




}
